package com.example.day02;

import java.lang.reflect.Array;
import java.util.Arrays;

public class TwoArrayDemo {
    public static void main(String[] args) {
        String[][] arr = {{"白","日","依","山","尽"},{"黄","河","入","海","流"},{"欲","穷","千","里","目"},{"更","上","一","层","楼"}};

         int []aa={1,2,3};
         int []bb={1,2,3};

        System.out.println(aa.toString());
        System.out.println(bb.toString());
        System.out.println(aa==bb);

        System.out.println(Arrays.toString(aa));
        System.out.println(Arrays.toString(bb));
        System.out.println(Arrays.equals(aa,bb));
        poem(arr);

        poemMethod(arr);


    }

    //横诗变竖诗
    public  static  void poem(String [][] arr){

        String [][]temp=new String[arr[0].length][arr.length];
        for(int i=0;i< arr.length;i++){
            for (int j=0;j<arr[i].length;j++){
                //行列交换
              temp[j][i]=arr[i][j];
            }
        }
        //五行四列
        for(int i=0;i< temp.length;i++){
            for (int j=0;j<temp[i].length;j++){
                System.out.print(temp[i][j]);
            }
            System.out.println();
        }
    }
    //一维数组实现  行列交换诗集
    public  static  void  poemMethod(String [][]arr){
        String [] atemp=new String[arr.length*arr[0].length];

        int length = 0;

        for(int i=0;i<arr.length;i++){
            for(int j=0;j<arr[i].length;j++){
                atemp[length++]=arr[i][j];
            }
        }
        System.out.println(Arrays.toString(atemp));
        //[白, 日, 依, 山, 尽, 黄, 河, 入, 海, 流, 欲, 穷, 千, 里, 目, 更, 上, 一, 层, 楼]

        String [][] newarr= new String[arr[0].length][arr.length];
        for(int i=0;i< newarr.length;i++){
            for(int j=0;j<newarr[i].length;j++){
                /**
                 * 0 5 10 15
                 * 1 6  11 16
                 *  . . . .
                 */

                newarr[i][j]=atemp[i+j*5];
            }
        }
        for (int i=0;i< newarr.length;i++){
            for(int j=0;j<newarr[i].length;j++){
                System.out.print(newarr[i][j]);
            }
            System.out.println();
        }

    }


}
